import {observable} from 'mobx'
import {fetchGoodsList} from '@/api/goods'

export default observable({
  totalList: [],
  cate: '',
  total: -1,
  loaded: false,
  getGoodsList(data = {}) {
    (this.cate !== data.cate || data.page == 1) && (this.totalList = [], data.page=1, this.cate = data.cate, this.total = -1, this.loaded = false)
    this.total != this.totalList.length ? fetchGoodsList(data).then(res => {
      this.total = res.total
      this.totalList.push(...res.list)
      console.log(this.total);
      (this.total === this.totalList.length || this.total == 0) ? this.loaded = true : this.loaded = false
    }) : this.total != 0 ? this.loaded = false : this.loaded = true

   }


})